home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snpd1292.zip / CPUCHECK.ASM < prev    next >
Assembly Source File  |  1992-12-26  |  2KB  |  64 lines

  1.         page    55, 132
  2.  
  3. ;  FUNCTION:  cpu_check
  4. ;
  5. ;  Attempt to discover the type of CPU. Use MASM 5.1 or greater.
  6. ;  Returns 86 for 8088/8086, 286 for 80286, 386 for 80386/80486.
  7. ;
  8. ;  Requires MASM 5.1 or later or equivalent
  9. ;
  10. ;  Assemble with:       MASM /Mx /z ...
  11. ;                       TASM /jMASM /mx /z ...
  12. ;
  13.  
  14. %       .MODEL  memodel,C               ;Add model support via
  15.                                         ;command line macros, e.g.
  16.                                         ;MASM /Dmemodel=LARGE
  17.  
  18.         .CODE
  19. ;
  20. ; int cpu_check(void) - returns 86, 186, 286, 386
  21. ;
  22.  
  23.         PUBLIC  cpu_check
  24.  
  25. cpu_check       PROC    USES BX
  26.         pushf
  27.         xor     ax,ax                   ; zero ax
  28.         push    ax
  29.         popf                            ; try to put 0 into flags
  30.         pushf
  31.         pop     ax                      ; see what went in flags
  32.         and     ax,0f000h               ; mask off high flag bits
  33.         cmp     ax,0f000h               ; was high nibble ones
  34.         je      _86                     ; is 8086 or 8088
  35.         push    sp                      ; see if sp is updated
  36.         pop     bx                      ; before or after it is
  37.         cmp     bx,sp                   ; pushed
  38.         jne     _186
  39.         mov     ax,0f000h               ; try to set high bits
  40.         push    ax
  41.         popf                            ; in the flags
  42.         pushf
  43.         pop     ax                      ; look at actual flags
  44.         and     ax,0f000h               ; any high bits set?
  45.         je      _286                    ; is 80286
  46. _386:
  47.         mov     ax,386                  ; is an 80386
  48.         jmp     ccexit
  49. _286:
  50.         mov     ax,286                  ; is an 80286
  51.         jmp     ccexit
  52. _186:
  53.         mov     ax,186                  ; is an 80188/80186
  54.         jmp     ccexit
  55. _86:
  56.         mov     ax,86                   ; is an 8088/8086
  57. ccexit:
  58.         popf                            ; restore original flags
  59.         ret                             ; return
  60.  
  61. cpu_check       ENDP    
  62.  
  63.         end
  64.